<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input type="text" id="msg">
<button onclick="send()">发送</button>

</body>


<script>


    var socket = new WebSocket("ws://127.0.0.1:7777/ws");
    // 收到服务端得消息
    socket.onmessage = function(event){
        console.log(event.data)

    };
    socket.onopen = function(event){
        console.log("建立连接"+event.data)
    };
    socket.onclose = function(event){
    };

    function send(){
        var msg = document.getElementById("msg").value
        socket.send(msg)
    }
</script>
</html>